package com.hzqy.persistence.dao.activity;

import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Repository;

import com.hzqy.persistence.dao.core.PersistenceDao;
import com.hzqy.web.vo.PmsUserVo;
import com.hzqy.web.vo.activity.AnswerUserVo;
import com.hzqy.web.vo.activity.AwardUserVo;

@Repository
public class ActivityDrawDao extends PersistenceDao<PmsUserVo, Integer>{
	/**
	 * 获取用户抽奖电话号码
	 * @param awardUserVo
	 * @return
	 */
	public String getDrawPhone(Map map){
		String phone = "";
		try{
			phone = (String) getSqlSession().selectOne(this.getNamespace() +  "getAwardPhone", map);
			return phone;
		}catch(Exception e){
			LOG.error("查询用户抽奖电话号码失败",e);
			return "";
		}
	}
	/**
	 * 查询抽奖中奖名单
	 * @return
	 */
	public List<AwardUserVo> awardUserList(Map map){
		return getSqlSession().selectList(this.getNamespace() + "awardUserList", map);
	}
	/**
	 * 插入用户抽奖记录
	 * @param awardUserVo
	 * @return
	 */
	public int insertAwardResult(AwardUserVo awardUserVo){
		getSqlSession().insert(this.getNamespace() +"insertAwardResult", awardUserVo);
		int id=awardUserVo.getF_au_id();
		LOG.debug("insertAwardResult-id:"+id+"--"+awardUserVo.getF_au_id());
		return id;
	}
	/**
	 * 修改中奖用户手机号码
	 * @param map
	 * @return
	 */
	public int updateAwardPhone(Map map){
		return getSqlSession().update(this.getNamespace() + "updateAwardPhone", map);
	}
	/**
	 * 查询用户抽奖次数(天)
	 * @param awardUserVo
	 * @return
	 */
	public int getDrawCountDay(Map map){
		return getSqlSession().selectOne(this.getNamespace() + "getDrawCountDay", map);
	}
	/**
	 * 查询用户抽奖次数(周)
	 * @param awardUserVo
	 * @return
	 */
	public int getDrawCountWeek(Map map){
		return getSqlSession().selectOne(this.getNamespace() + "getDrawCountWeek", map);
	}
	/**
	 * 获取指定时间内的抽奖中奖用户人数(天)
	 * @param awardUserVo
	 * @return
	 */
	public int getAwardDrawCountDay(Map map){
		return getSqlSession().selectOne(this.getNamespace() + "getAwardDrawCountDay", map);
	}
	/**
	 * 获取指定时间内的抽奖中奖用户人数(周)
	 * @param awardUserVo
	 * @return
	 */
	public int getAwardDrawCountWeek(Map map){
		return getSqlSession().selectOne(this.getNamespace() + "getAwardDrawCountWeek", map);
	}
	
	public List<AwardUserVo> selectUseraward(AwardUserVo awardUserVo) {
		return getSqlSession().selectList(this.getNamespace() + "selectUseraward", awardUserVo);
	}
	
	public int selectCountByOrg(AnswerUserVo answerUserVo) {
		return getSqlSession().selectOne(this.getNamespace() + "selectCountByOrg", answerUserVo);
	}
	
	public int selectCountByServerId(AnswerUserVo answerUserVo) {
		return getSqlSession().selectOne(this.getNamespace() + "selectCountByServerId", answerUserVo);
	}
}
